<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<title>${title}</title>
<%@include file="/WEB-INF/templates/common/common.jsp"%>
<style>
	td{border:1px solid red;text-align:center}
</style>
<script type="text/javascript" src="${basePath}/static/page/js/jqPaginator.js"></script>
<script type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
<script  type="text/javascript" src="${basePath}/static/js/util.js"></script>
<script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_style.css" rel="stylesheet" type="text/css">

</head>
<body>

</head>
<body>
 <!--头部-->
 <%@include file="/WEB-INF/templates/common/header.jsp"%>

<!------导航条-->
 <%@include file="/WEB-INF/templates/common/navigation.jsp"%>

<div class="list_main lay_out">
 <div class="list_DH">
    <!--打印模块导航栏-->
 <%@include file="/WEB-INF/templates/common/printnav.jsp"%>
 </div>
 <div class="list_NR">
  <div class="loc">
   <h3>打印申请</h3>
  </div>
 
  <div class="list_con_table"> 
   <div class="search_table">
    <ul id="table_ul">
    <li class="Label_1" style="width:15%">病案所属人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="40" name='name' id='name' value='${count}' /></li>
    <li class="Label_1" style="width:12%">就诊标示：</li>
    <li class="Label_2"><input class="input_box" type="text"  maxlength="60" name='idNumber' id='idCard' value='' /></li>
     <li class="Label_1">预约方式：</li>
    <li class="Label_2"><select style="width:100px;height:30px"><option>web窗口</option><option>微信预约</option></select></li>
    <li class="Label_5">
       <a onclick="selectChose()">选中申请</a> 
	   <a onclick="findMr(1,10)">查询</a>
    </li>
    </ul>
  </div>
  <table class="Search_tableList" cellpadding="0" cellspacing="0">
		      <tr>
		      <td class="tdLabel_4">序号</td>
		      <td class="tdLabel_4">姓名</td>
		      <td class="tdLabel_4">身份证号</td>
		       <td class="tdLabel_4">就诊类型</td>
		      <td class="tdLabel_4">就诊机构</td>
		      <td class="tdLabel_4">就诊标示记录</td>
		      <td class="tdLabel_4">出院时间</td>
		      <td class="tdLabel_4">全选&nbsp;<input type="checkbox" name="all" onchange="checkAll(this)"></td>
		      </tr>
		      <tbody id="tbody">
		
		      </tbody>
     </table>
    <div class="pageList">
       <ul class="pagination clearfix" id="page_plus"></ul>
       <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
       </div>          
    </div>
 </div>
</div>
</div>
<!--页脚部分-->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>
 <script>
    /* var mrId;
 	var name;
   */
 	function findMr(pageNo,pageSize){
 	
 		var name=$("#name").val();		
 		var idCard=$("#idCard").val();
 		if((name==null || name=='')&&(idCard==null || idCard=="")){
 			layer.alert('查询条件不能为空', {icon: 0});
 			return;
 		}
 		//{"hospitalizationNotes":[{"mr_id":"0158981","id_number":"130625284798787009","treatment_type_name":"住院","out_hospital_date":"2017-09-24","name":"赵尊号","id":5,"first_level_medical_guid":"ad820cdb37fc493aa820caa4c36c8cfd","hospital_name":"山东省立医院"}],"medRecordQuery":{"currentStartNum":0,"totalPages":1,"name":"赵尊号","pageSize":1,"currentPage":1,"totalCounts":1}}
 		jQuery.support.cors = true;
 		$.ajax({
 			type:"get",
 			url:"${corePath}/medrecord/queryMedrecordOfPrinterByAjax",
 			data:{name:name,idCard:idCard,currentPage:pageNo,pageSize:pageSize},
 			success:function(data){
	 			if(data.success){
	 				console.log(typeof(data));
	 				initPage(data.data.medRecordQuery.totalCounts,pageSize,pageNo);
	 				var hospitalizationNotes=data.data.hospitalizationNotes;
	 				var len=hospitalizationNotes.length;
	 				if(len>0){
		 				var html="";
		 				for(var i=0;i<hospitalizationNotes.length;i++){
		 					var mrBasic=hospitalizationNotes[i];
		 					html+="<tr>"+
		 					      "	<td class='tdLabel_5'>"+((parseInt(i)+1)+(parseInt(pageNo)*pageSize))+"</td>"+
		 					      " <td  class='tdLabel_5'>"+mrBasic.name+"</td>"+
		 					      " <td  class='tdLabel_5'>"+mrBasic.id_number+"</td>"+
		 					   	  " <td  class='tdLabel_5'>"+mrBasic.treatment_type_name+"</td>"+
		 					      " <td  class='tdLabel_5'>"+mrBasic.hospital_name+"</td>"+
		 					      " <td  class='tdLabel_5'>"+mrBasic.mr_id+"</td>"+
		 					      " <td  class='tdLabel_5'>"+mrBasic.out_hospital_date+"</td>"+
		 					      " <td  class='tdLabel_5'>"+
		 					      "	 <input type='checkbox' name='mrIds' mrId='"+mrBasic.mr_id+"' treatment='"+mrBasic.treatment_type_name+"'  firstGuid='"+mrBasic.first_level_medical_guid+"'  mrName='"+mrBasic.name+"' idCard='"+mrBasic.id_number+"' orgName='"+mrBasic.hospital_name+"'  outTime='"+mrBasic.out_hospital_date+"'/></td>"+
		 					      "</tr>";
		 				}
		 				$("#tbody").html(html);	
	 				}else{
	 					layer.alert('查询数据为空', {icon: 5});
	 	 				$("#tbody").html("");
	 				}
	 			}
 			}
 		})
 	}
 	
 	
 	//批量选中checkbox
 	function checkAll(obj){
 		var $this=$(obj);
 		if($this.is(':checked')){
 			$("input[type='checkbox'][name='mrIds']").each(function(){
 				$(this).prop("checked",true);
			});
 		}else{
 			$("input[type='checkbox'][name='mrIds']").each(function(){
 				$(this).prop("checked",false);
			});
 		}
 	}
 	
 	
 	function getHosOffice(){
 		$.ajax({
 			type:"post",
 			url:"${basePath}/direct/getHospitals",
 			success:function(data){
 				
 				if(data!=null){
 					var html="";
 					for(var i in data){
 						html+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
 					}
 					$("#hospitalId").html(html);
 				}else{
 					$("#hospitalId").html("");
 					
 				}
 			}
 		});
 	}
 	
 	function getOffice(){
 		var hospitalId= $("#hospitalId").val();
 		$.ajax({
 			type:"post",
 			url:"${basePath}/direct/getOffices",
 			data:{hospitalId:hospitalId},
 			success:function(data){
 			$("#outDeptId").html("");
 			var html="<option value=''>--------选中科室--------</option>   ";
 				if(data!=null){
 					for(var i in data){
 						html+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
 					}
 					$("#outDeptId").html(html);
 				}else{
 					$("#outDeptId").html("");
 				}
 			}
 		})
 	}
 
 	//获取checkbox值
	 function getFormVals(name){
			var arr = [];
			$("input[type='checkbox'][name='"+name+"']:checked").each(function(){
				arr.push($(this).val());	
			});
			return arr.toString();
	}
	 
	 //选中申请
	 function selectChose(){
		
		var arr=[];
		 
		 $("input[type='checkbox'][name='mrIds']:checked").each(function(){
				var $this=$(this);
				// firstGuid='"+mrBasic.first_level_medical_guid+"'  mrName='"+mrBasic.name+"' idCard='"+mrBasic.id_number+"' orgName='"+mrBasic.hospital_name+"'  outTime='"+mrBasic.out_hospital_date+"'
		
				var name=$this.attr("mrName");
				var firstGuid=$this.attr("firstGuid");
				var idCard=$this.attr("idCard");
				var orgName=$this.attr("orgName");
				var outTime=$this.attr("outTime");
				var treatment=$this.attr("treatment");
				var mrId=$this.attr("mrId");
				arr.push({name:name,firstGuid:firstGuid,idCard:idCard,orgName:orgName,outTime:outTime,treatment:treatment,mrId:mrId});
				
				
			});
		
		 $.ajax({
		 	type:"post",
		    contentType : 'application/json;charset=utf-8', //设置请求头信息
            dataType:"json",
            data: JSON.stringify(arr),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
            url:"${basePath}/print/getMrListByMrId",
		 	success:function(data){
		 		console.log(data)
		 		//alert(data.result);
		 		window.location.href="${basePath}/print/applyPrintShow";
		 		
		 	},
		 	error:function(data){
		 		//alert(JSON.stringify(data));
		 	}
		 })
	 }
		 
	function getPrintCopys(obj){
		var options=$("#copies option:selected");  //获取选中的项
		var $this=$(obj);
		var mrId=$this.attr("mrId");
		var copies= $("#printCopies").val();
		if(copies==null || copies==""){		
			var newmrId=mrId+"-"+options.val();
		}else{
			var newmrId=","+mrId+"-"+options.val();
		}
		copies += newmrId;
		$("#printCopies").val(copies);
	}
	
	
	
	function page(currentPage,totalCounts){
	
	var totalCounts = totalCounts;
 		var pageSize = 10;
 		var totalPages = Math.ceil(totalCounts/pageSize);
 		//var currentPage = 1;
 		$("#ston_page_msg").text(totalPages);
 		/* $(".number").keypress(function(event) {  
 			 var ev = event.which?event.which:window.event.keyCode;
 			  if(ev>=48&&ev<=57){
 				return true;  
 			  }else if(ev==8 || ev==13 || ev==46){
 				return true;  
 			  }else{
 				return false;
 			  } 
 		}).focus(function() {  
 			this.style.imeMode='disabled';  
 		}); */  
 		$("#Pagination").pagination(totalPages,{
 		current_page:currentPage,
 	  callback: function (page_index,jp) {
 	 	 //currentPage=page_index;
 		findMr(page_index,pageSize);
 	  } //PageCallback() 为翻页调用次函数。
 	  
 	  });
	}
	
	$(document).ready(function() {
 		
 		 getHosOffice();
 		
 		
 	});
  //分页
	function initPage(totalCounts,pageSize,currentPage){
		 var visiblePages = 5;
		 var totalPages =Math.ceil(totalCounts/pageSize);
		 $("#totalPage").html(totalCounts);
		 if(totalCounts < 1){
		 	$("#currentPage").html(0+"/"+totalPages);
		 	$("#page_plus").html("");
		 	return;
		 }
		 
         $("#currentPage").html(currentPage+"/"+totalPages);
         
		 $('#page_plus').jqPaginator({

		        totalCounts: totalCounts,
		        pageSize:pageSize,
		        visiblePages: visiblePages,
		        currentPage: currentPage,

		        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		        onPageChange: function (page,type) {
		        	if(type !='init'){
		        		findMr(page,pageSize);
			        }
		        }
		    });

	}	
	 
	
	</script>

</body>
</html>
